// -----------------------------------------------------------------------------
// all group 
// _playtype 参考 RateConfig_5h $this->playGroupArr 对应
// -----------------------------------------------------------------------------
var M = new Object();
M.Rates = new Array();
M.RatesTimeId = 0;
M.rateI = 0;
M.rdoRCID = '';
$.fn.getAjaxRatedata = function(_lotto_id, _gametype, _playtype) {
    if (M.RatesTimeId) {
        clearTimeout(M.RatesTimeId);
    }
    $().disAreaObj();
    var tempStr = '';
    if (_playtype == 'rc') {
        var rdoRCID = $('input[name="rcbettype"]:checked').val();
        if (rdoRCID == undefined) {
            rdoRCID = _rcbettype;
            $('input[name="rcbettype"][value="' + _rcbettype + '"]').attr('checked', 'true');
        } // '10'
        tempStr = '&bid=' + rdoRCID;
        if (M.rdoRCID != rdoRCID) {
            M.Rates = new Array();
            M.rdoRCID = rdoRCID;
        }
    }
    // debug window.open('op.php?op=xml_3d&fp=rate_5h&playtype=' + _playtype + '&lotto_id_5h=' + _lotto_id + "&gametype=" + _gametype + "&disk="+ $("select#slcDisk").val() + tempStr );
    $.getJSON('op.php?op=xml_3d&fp=rate_5h&playtype=' + _playtype + '&lotto_id_5h=' + _lotto_id + "&gametype=" + _gametype + "&disk=" + $("select#slcDisk").val() + tempStr, function(ratedata) {
        var dataLen = 0;
        var urlPre = "";
        var hrefStr = "";
        M.rateI = 0;
        if (ratedata == undefined) {
            $("div#errormsg").addClass("error").text("系统维护中");
        } else if (ratedata.errormsg != undefined) {
            $("div#errormsg").addClass("error").text("No Rate data");
        } else {
            var xyid = $("select#xyidSlc").val();
            var disk = $("select#slcDisk").val();
            //show table & ratedata
            //$().showTableData(ratedata,_lotto_id,_gametype,_playtype,xyid,disk);
            var htmStr = "";
            switch (_playtype) {
                case 'r1':
                    htmStr = show_r1(ratedata, _lotto_id, _gametype, _playtype, xyid, disk);
                    break;
                case 'rp1':
                case 'rp2':
                case 'rp3':
                case 'rp4':
                case 'rp5':
                case 'rp6':
                case 'rp7':
                case 'rp8':
                    htmStr = show_rpx(ratedata, _lotto_id, _gametype, _playtype, xyid, disk);
                    break;
                case 'rc':
                    htmStr = show_rxcx(ratedata, _lotto_id, _gametype, _playtype, xyid, disk);
                    break
                default:
                    htmStr = 'error show data';
                    $("#myDivTbl").html(htmStr);
                    return false;
                    break;
            }
            $("#myDivTbl").html(htmStr);
        }

        $().redisAreaObj();
        $("div#mainPageData").show();
        $("div#errormsg").text("");
        // change text or checkbox type
        var timebtnType = $("input:hidden#timebtnType").val();
        if (timebtnType == "checkbox") {
            $().timebtnTypeToCheckbox();
            var rdoRCID = ',' + $('input[name="rcbettype"]:checked').val() + ',';
            var chkRdoStr = ',12,15,';
            $('#setMyNum2').css('display', '');
            if (chkRdoStr.indexOf(rdoRCID) > -1) {
                $('#setMyNum2').css('display', 'none');
                $('#tblMy3DAreaS input:checkbox').click(function() {
                    var chkVal = $(this).attr('checked');
                    if (chkVal) {
                        $(this).addTheValClr(null, '')
                    }
                    else {
                        $(this).clrTheValClr(null);
                    }
                    computeUnionS(); // count Group numbers For Super
                });
                $('#btnCopyToOther').click(function() {
                    var sendDataArr = [];
                    var L = $('#tbdData_0 input:checked').length;
                    if (L > 6) {
                        $().showMyMsgBox('包牌时,最多只能勾选六个号码!');
                        return false;
                    }
                    $('#tbdData_0 input:checked').each(function(idx, oVal) {
                        sendDataArr.push($(oVal).val());
                        return true;
                    });
                    var tbdNum = $('#tblMy3DAreaS tbody').length;
                    for (var i = 1; i < tbdNum; i++) {
                        $('#tbdData_' + i + ' input').css('background-color', '').val(sendDataArr).filter(':checked').addTheValClr(null, '');
                    }
                    computeUnionS();
                });

            } else {
                $('#tblMy3DArea input:checkbox').click(function() {
                    var chkVal = $(this).attr('checked');
                    if (chkVal) {
                        $(this).addTheValClr(null, '')
                    }
                    else {
                        $(this).clrTheValClr(null);
                    }
                    computeUnion(); // count Group numbers
                });
            }
        } else {
            $('#tblMy3DArea input:text').change(function() {
                var chkVal = $(this).val();
                if (chkVal != '') {
                    $(this).addTheValClr(null, '')
                }
                else {
                    $(this).clrTheValClr(null);
                }
            });
        }

        // $("#tblMy3DArea td:has(input)").parent("tr.td2").hover(
        //   function() {$(this).children().addClass("trover");}
        //   , function() {$(this).children().removeClass("trover");}
        //  );
        $('#myreset').click();
        // check rate each 30 sec
        if (_timestap > 0)
        {
            M.ReNewTime = Math.floor((Math.random() * 100) % 30 + 30) * 1000;
            M.RatesTimeId = setTimeout("$().getAjaxRatedata(" + _lotto_id + "," + _gametype + ",'" + _playtype + "');", M.ReNewTime);
        } else if (M.RatesTimeId) {
            clearTimeout(M.RatesTimeId);
        }

    });
};

// show table data
// jason data format={"bXX":{"number":["01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21"],
//                          "rates":[1.92,1.92,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00]},
// eazy type
function show_r1(rdata, _lotto_id, _gametype, _playtype, xyid, disk) {
    var sStr = '<table id="tblMy3DArea"  border="0" cellSpacing="1" cellPadding="0">';
    var showBetSubArr = '';
    var i = 0;
    var l = 0;
    var oShow = '';
    var showTitleArr05 = [['大', '小'], ['单', '双'], ['尾大', '尾小'], ['合单', '合双']];
    var subidArr = '';
    var sTitle = '';
    var subidShow = '';
    var showBetSubArr = '';


    sStr += '<tbody id="tbdData">';

    // Dragon and tiger
    sStr += '<tr><td colspan="4" class="bgImg_' + _gametype + '" style="padding:3px;text-align:center;" >总和, 龙虎</td></tr>';
    sStr += '<tr class="td2">';
    showBetSubArr = [
        ['', [rdata.b8], [8], [0], [['总大', '总小']], 1, '']
                , ['', [rdata.b7], [7], [0], [['总单', '总双']], 1, '']
                , ['', [rdata.b9], [9], [0], [['总尾大', '总尾小']], 1, '']
                , ['', [rdata.b18], [18], [0], [['龙', '虎']], 1, '']
    ];
    for (i = 0, l = showBetSubArr.length; i < l; i++) {
        oShow = showBetSubArr[i];
        sStr += '<td>';
        sStr += crt_2face_com_Vertical(oShow[1], oShow[2], oShow[3], oShow[0], oShow[4], oShow[5], 4, disk, _playtype, oShow[6], xyid);
        sStr += '</td>';
    }
    sStr += '</tr>';

    // ball 1-4
    sStr += '<tr>';
    showBetSubArr = [
        ['第一球', [rdata.b2_1, rdata.b1_1, rdata.b3_1, rdata.b4_1], [2, 1, 3, 4], [1, 1, 1, 1], showTitleArr05, 1, '']
                , ['第二球', [rdata.b2_2, rdata.b1_2, rdata.b3_2, rdata.b4_2], [2, 1, 3, 4], [2, 2, 2, 2], showTitleArr05, 1, '']
                , ['第三球', [rdata.b2_3, rdata.b1_3, rdata.b3_3, rdata.b4_3], [2, 1, 3, 4], [3, 3, 3, 3], showTitleArr05, 1, '']
                , ['第四球', [rdata.b2_4, rdata.b1_4, rdata.b3_4, rdata.b4_4], [2, 1, 3, 4], [4, 4, 4, 4], showTitleArr05, 1, '']
    ];
    for (i = 0, l = showBetSubArr.length; i < l; i++) {
        oShow = showBetSubArr[i];
        sStr += '<td>';
        sStr += crt_2face_com_Vertical(oShow[1], oShow[2], oShow[3], oShow[0], oShow[4], oShow[5], 4, disk, _playtype, oShow[6], xyid);
        sStr += '</td>';
    }
    sStr += '</tr>';

    // ball 5-8
    sStr += '<tr class="td2">';
    showBetSubArr = [
        ['第五球', [rdata.b2_5, rdata.b1_5, rdata.b3_5, rdata.b4_5], [2, 1, 3, 4], [5, 5, 5, 5], showTitleArr05, 1, '']
                , ['第六球', [rdata.b2_6, rdata.b1_6, rdata.b3_6, rdata.b4_6], [2, 1, 3, 4], [6, 6, 6, 6], showTitleArr05, 1, '']
                , ['第七球', [rdata.b2_7, rdata.b1_7, rdata.b3_7, rdata.b4_7], [2, 1, 3, 4], [7, 7, 7, 7], showTitleArr05, 1, '']
                , ['第八球', [rdata.b2_8, rdata.b1_8, rdata.b3_8, rdata.b4_8], [2, 1, 3, 4], [8, 8, 8, 8], showTitleArr05, 1, '']
    ];
    for (i = 0, l = showBetSubArr.length; i < l; i++) {
        oShow = showBetSubArr[i];
        sStr += '<td>';
        sStr += crt_2face_com_Vertical(oShow[1], oShow[2], oShow[3], oShow[0], oShow[4], oShow[5], 4, disk, _playtype, oShow[6], xyid);
        sStr += '</td>';
    }
    sStr += '</tr>';
    sStr += '</tbody>';
    sStr += '</table>';
    return sStr;
}

// bettype=7,8
function show_r1_old(rdata, _lotto_id, _gametype, _playtype, xyid, disk) {
    var sStr = '<table class="tblMy3D" id="tblMy3DArea" style="table-layout:fixed; ">';
    var showBetSubArr = '';
    var htmlTitle = '<td>号码</td><td>赔率</td><td>金额</td>';
    var i = 0;
    var l = 0;
    var oShow = '';
    var showTitleArr03 = [['总单', '总双'], ['总大', '总小']];
    var showTitleArr04 = [['龙', '虎'], ['总尾大', '总尾小']];
    var showTitleArr05 = [['大', '小'], ['单', '双']];
    var showTitleArr06 = [['尾大', '尾小'], ['合单', '合双']];
    var subidArr = '';
    var sTitle = '';
    var subidShow = '';
    var showBetSubArr = [
        ['总和', [rdata.b7, rdata.b8], [7, 8], [0, 0], showTitleArr03, 1, '']
                , ['龙虎', [rdata.b18, rdata.b9], [18, 9], [0, 0], showTitleArr04, 1, '']
                , ['第一球', [rdata.b2_1, rdata.b1_1], [2, 1], [1, 1], showTitleArr05, 2, '']
                , ['第二球', [rdata.b2_2, rdata.b1_2], [2, 1], [2, 2], showTitleArr05, 2, '']
                , ['第三球', [rdata.b2_3, rdata.b1_3], [2, 1], [3, 3], showTitleArr05, 2, '']
                , ['第四球', [rdata.b2_4, rdata.b1_4], [2, 1], [4, 4], showTitleArr05, 2, '']
                , ['第五球', [rdata.b2_5, rdata.b1_5], [2, 1], [5, 5], showTitleArr05, 2, '']
                , ['第六球', [rdata.b2_6, rdata.b1_6], [2, 1], [6, 6], showTitleArr05, 2, '']
                , ['第七球', [rdata.b2_7, rdata.b1_7], [2, 1], [7, 7], showTitleArr05, 2, '']
                , ['第八球', [rdata.b2_8, rdata.b1_8], [2, 1], [8, 8], showTitleArr05, 2, '']
                , ['第一球', [rdata.b3_1, rdata.b4_1], [3, 4], [1, 1], showTitleArr06, 1, '']
                , ['第二球', [rdata.b3_2, rdata.b4_2], [3, 4], [2, 2], showTitleArr06, 1, '']
                , ['第三球', [rdata.b3_3, rdata.b4_3], [3, 4], [3, 3], showTitleArr06, 1, '']
                , ['第四球', [rdata.b3_4, rdata.b4_4], [3, 4], [4, 4], showTitleArr06, 1, '']
                , ['第五球', [rdata.b3_5, rdata.b4_5], [3, 4], [5, 5], showTitleArr06, 1, '']
                , ['第六球', [rdata.b3_6, rdata.b4_6], [3, 4], [6, 6], showTitleArr06, 1, '']
                , ['第七球', [rdata.b3_7, rdata.b4_7], [3, 4], [7, 7], showTitleArr06, 1, '']
                , ['第八球', [rdata.b3_8, rdata.b4_8], [3, 4], [8, 8], showTitleArr06, 1, '']
    ];
    //sStr += '<tr class="bgClc_' + _gametype + '"><td>类别</td>' + htmlTitle+ htmlTitle+ htmlTitle+ htmlTitle + '</tr>';
    sStr += '<tr class="bgImg_' + _gametype + '"><td colspan="13">总和, 龙虎</td></tr>';
    for (i = 0, l = showBetSubArr.length; i < l; i++) {
        oShow = showBetSubArr[i];
        if (i == 2) {
            sStr += '<tr class="bgClc_' + _gametype + '"><td>类别</td>' + htmlTitle + htmlTitle + htmlTitle + htmlTitle + '</tr>';
        }
        sStr += crt_2face_com(oShow[1], oShow[2], oShow[3], oShow[0], oShow[4], oShow[5], 4, disk, _playtype, oShow[6], xyid);
    }
    sStr += '</table>';
    return sStr;
}

function show_rpx(rdata, _lotto_id, _gametype, _playtype, xyid, disk) {
    var sStr = '<table class="tblMy3D" id="tblMy3DArea" width="700">';
    var showBetSubArr = '';
    var i = 0;
    var l = 0;
    var oShow = '';
    var showTitleArr = [['单', '双'], ['大', '小']];
    var showTitleArr02 = [['合单', '合双'], ['尾大', '尾小']];
    var showTitleArr03 = [['总单', '总双'], ['总大', '总小']];
    var showTitleArr04 = [['东', '南', '西', '北']];
    var showTitleArr05 = [['中', '发', '白']];
    var subidArr = '';
    var sTitle = '';
    var subidShow = '';
    switch (_playtype) {
        case 'rp1':
            sTitle = '第一球';
            subidShow = 1;
            break;
        case 'rp2':
            sTitle = '第二球';
            subidShow = 2;
            break;
        case 'rp3':
            sTitle = '第三球';
            subidShow = 3;
            break;
        case 'rp4':
            sTitle = '第四球';
            subidShow = 4;
            break;
        case 'rp5':
            sTitle = '第五球';
            subidShow = 5;
            break;
        case 'rp6':
            sTitle = '第六球';
            subidShow = 6;
            break;
        case 'rp7':
            sTitle = '第七球';
            subidShow = 7;
            break;
        case 'rp8':
            sTitle = '第八球';
            subidShow = 8;
            break;
        default :
            return '-rpn error-';
    }
    var showBetSubArr = [
        ['', [rdata.b1, rdata.b2], [1, 2], [subidShow, subidShow], showTitleArr, 1, ''] // sTitle
                , ['', [rdata.b4, rdata.b3], [4, 3], [subidShow, subidShow], showTitleArr02, 1, ''] // 合单双
                , ['', [rdata.b6], [6], [subidShow], showTitleArr04, 1, 'four5h0'] // 方位
                , ['', [rdata.b5], [5], [subidShow], showTitleArr05, 1, 'color5h0'] // 中发白
    ];
    sStr += crt_1To21(rdata.b0, 0, subidShow, sTitle, 4, disk, _playtype, xyid);
    sStr += '<tr><th colspan="18" class="bgClc_' + _gametype + '" style="font-family:Arial;font-size:0.95em;">' + sTitle + ' 双面盘</th></tr>';
    for (i = 0, l = showBetSubArr.length; i < l; i++) {
        oShow = showBetSubArr[i];
        sStr += crt_2face_com(oShow[1], oShow[2], oShow[3], oShow[0], oShow[4], oShow[5], 5, disk, _playtype, oShow[6], xyid);
    }

    sStr += '</table>';
    return sStr;
}

function show_rxcx(rdata, _lotto_id, _gametype, _playtype, xyid, disk) {
    var rdoRCID = $('input[name="rcbettype"]:checked').val();
    if (rdoRCID == undefined) {
        rdoRCID = _rcbettype;
    } // 10
    var radValArr = [[10, '选二任选'], [11, '选二连组'], [12, '选二连直'], [13, '选三任选'], [14, '选三前组'], [15, '选三前直'], [16, '选四任选'], [17, '选五任选']];
    switch (rdoRCID) {
        case '10':
            _rxcxChkN = 1;
            _maxPoun = 10;
            return crt_rdoRC(radValArr, rdoRCID, rdata.mbBet) + crt_1To21ChkBox(rdata.b10, 10, 0, radValArr[0][1], 4, disk, _playtype);
            break;
        case '11':
            _rxcxChkN = 1;
            _maxPoun = 10;
            return crt_rdoRC(radValArr, rdoRCID, rdata.mbBet) + crt_1To21ChkBox(rdata.b11, 11, 0, radValArr[1][1], 4, disk, _playtype);
            break;
        case '12':
            _rxcxChkN = 1;
            _maxPoun = 20;
            return crt_rdoRC(radValArr, rdoRCID, rdata.mbBet) + crt_1To21ChkBoxByP(rdata.b12, 12, 0, radValArr[2][1], 3, disk, _playtype, ['前<br />位', '后<br />位']);
            break;
        case '13':
            _rxcxChkN = 2;
            _maxPoun = 10;
            return crt_rdoRC(radValArr, rdoRCID, rdata.mbBet) + crt_1To21ChkBox(rdata.b13, 13, 0, radValArr[3][1], 4, disk, _playtype);
            break;
        case '14':
            _rxcxChkN = 2;
            _maxPoun = 10;
            return crt_rdoRC(radValArr, rdoRCID, rdata.mbBet) + crt_1To21ChkBox(rdata.b14, 14, 0, radValArr[4][1], 4, disk, _playtype);
            break;
        case '15':
            _rxcxChkN = 2;
            _maxPoun = 20;
            return crt_rdoRC(radValArr, rdoRCID, rdata.mbBet) + crt_1To21ChkBoxByP(rdata.b15, 15, 0, radValArr[5][1], 3, disk, _playtype, ['前<br />位', '中<br />位', '后<br />位']);
            break;
        case '16':
            _rxcxChkN = 3;
            _maxPoun = 8;
            return crt_rdoRC(radValArr, rdoRCID, rdata.mbBet) + crt_1To21ChkBox(rdata.b16, 16, 0, radValArr[6][1], 4, disk, _playtype);
            break;
        case '17':
            _rxcxChkN = 4;
            _maxPoun = 8;
            return crt_rdoRC(radValArr, rdoRCID, rdata.mbBet) + crt_1To21ChkBox(rdata.b17, 17, 0, radValArr[7][1], 4, disk, _playtype);
            break;
        default:
            return '-rncn error';
            break;
    }
}

function show_setMyNum2(_playtype) {
    switch (_playtype) {
        case 'rp1':
        case 'rp2':
        case 'rp3':
        case 'rp4':
        case 'rp5':
        case 'rp6':
        case 'rp7':
        case 'rp8':
            $('#setMyNum2').html(crt_quick02('a', [1, 1, 1, 1, 1]) + '<br />');
            break;
        case 'rc':
            $('#setMyNum2').html('<span id="B5hTypeSpan01Msg"></span>' + crt_quick([1, 1], 0) + '<span id="quick5hTypeSpana">' + crt_quick02('a', [1, 1, 1, 1, 1]) + '</span><span style="display:none;" id="quick5hTypeSpanb">' + crt_quick02('b', [0, 1, 1, 0, 0, 1]) + '</span><br /><input type="hidden" value="" name="B5hTypeSpan01" id="B5hTypeSpan01" /><input type="hidden" value="" name="B5hTypeSpan02" id="B5hTypeSpan02" /><input type="hidden" value="" name="B5hTypeSpan03" id="B5hTypeSpan03" /><input type="hidden" value="" name="B5hTypeMon" id="B5hTypeMon" />');
            $('#setMyNum3').html('<span id="B5hTypeSpan03Msg"></span>');
            break;
        default:
            return 0;
            break;
    }
    //$('<span>※ 连碰最多能勾选' + _maxPoun + '个碰数</span>').appendTo('#setMyNum2');
    $('input.quick5hType').click(function() {
        $('#B5hTypeSpan01Msg').empty();
        $('#B5hTypeSpan03Msg').empty();
        var timeBtnType = $("input:hidden#timebtnType").val();
        var attVal1 = '';
        var attVal2 = '';
        switch (timeBtnType) {
            case 'text':
                attVal1 = 'value';
                attVal2 = '*';
                break;
            case 'checkbox':
                attVal1 = 'checked';
                attVal2 = 'true';
                break;
            default:
                alert('error type');
                return false;
        }
        $("#tbdData input:[name^='b_']").clrTheValClr(attVal1);
        var sVal = $(this).val();
        var s2Val = '';
        if (sVal == 'a') {
            s2Val = 'b';
            _rxcxChkN02 = false;
        } else {
            s2Val = 'a';
            _rxcxChkN02 = true;
        }
        $('#quick5hTypeSpan' + s2Val).hide();
        $('#quick5hTypeSpan' + sVal).show();
    });
    $('#setMyNum2 input:button').click(function() {
        // type
        var timeBtnType = $("input:hidden#timebtnType").val();
        var attVal1 = '';
        var attVal2 = '';
        switch (timeBtnType) {
            case 'text':
                attVal1 = 'value';
                attVal2 = '*';
                break;
            case 'checkbox':
                attVal1 = 'checked';
                attVal2 = 'true';
                break;
            default:
                alert('error type');
                return false;
        }
        var oObj = $("#tbdData input:[name^='b_']");
        var myBtnId = $(this).attr('id').split("_")[1].split("");
        var sNumIdx = 3;
        if (_rxcxChkN02) {
            var chkData = $("#tbdData input:[name^='b_']:disabled:checked");
            if (chkData.length != _rxcxChkN) {
                alert('请至少勾选' + _rxcxChkN + '胆');
                return false;
            }
            $("#tbdData input:[name^='b_']:checked:not(:disabled)").clrTheValClr(attVal1);
        } else {
            oObj.clrTheValClr(attVal1);
        }
        switch (myBtnId[0]) {
            case 'A':
                var typeCharNum = myBtnId[1] % 2;
                oObj.filter(function(idx, ele) {
                    var myN = $(ele).attr('name').split("_");
                    var sNum = myN[sNumIdx];
                    if (sNum == 21) {
                        return false;
                    }
                    return (sNum % 2 == typeCharNum);
                }).addTheValClr(attVal1, attVal2);
                break;
            case 'B':
                var typeCharNum = myBtnId[1] - 1;
                oObj.filter(function(idx, ele) {
                    var myN = $(ele).attr('name').split("_");
                    var sNum = myN[sNumIdx];
                    if (sNum == 21) {
                        return false;
                    }
                    if (typeCharNum) {
                        return (sNum < 11);
                    }
                    else {
                        return (sNum > 10);
                    }
                }).addTheValClr(attVal1, attVal2);
                break;
            case 'C':
                var typeCharNum = myBtnId[1] % 2;
                oObj.filter(function(idx, ele) {
                    var myN = $(ele).attr('name').split("_");
                    var sNum = myN[sNumIdx];
                    if (sNum == 21) {
                        return false;
                    }
                    var sNum_1 = sNum.charAt(0) - 0;
                    var sNum_2 = sNum.charAt(1) - 0;
                    return ((sNum_1 + sNum_2) % 2 == typeCharNum);
                }).addTheValClr(attVal1, attVal2);
                break;
            case 'G':
                var typeCharNum = myBtnId[1] - 0;
                oObj.filter(function(idx, ele) {
                    var myN = $(ele).attr('name').split("_");
                    var sNum = myN[sNumIdx];
                    //if(sNum == 21){ return false;}
                    return (sNum.charAt(0) == typeCharNum);
                }).addTheValClr(attVal1, attVal2);
                break;
            case 'H':
                var typeCharNum = myBtnId[1] - 0;
                oObj.filter(function(idx, ele) {
                    var myN = $(ele).attr('name').split("_");
                    var sNum = myN[sNumIdx];
                    //if(sNum == 21){ return false;}
                    return (sNum.charAt(1) == typeCharNum);
                }).addTheValClr(attVal1, attVal2);
                break;
            case 'I':
                var typeCharNum = myBtnId[1] - 1;
                oObj.filter(function(idx, ele) {
                    var myN = $(ele).attr('name').split("_");
                    var sNum = myN[sNumIdx];
                    var subNum = 0;
                    if ((sNum % 7) == 0) {
                        subNum = 1;
                    }
                    if (typeCharNum == (Math.floor(sNum / 7) - subNum)) {
                        return true;
                    }
                    else {
                        return false;
                    }
                }).addTheValClr(attVal1, attVal2);
                break;
            case 'J':
                var typeCharNum = myBtnId[1];
                if (typeCharNum == 4) {
                    typeCharNum = 0;
                }
                oObj.filter(function(idx, ele) {
                    var myN = $(ele).attr('name').split("_");
                    var sNum = myN[sNumIdx];
                    if (typeCharNum == (sNum % 4)) {
                        return true;
                    }
                    else {
                        return false;
                    }
                }).addTheValClr(attVal1, attVal2);
                break;

            case 'K':
                oObj.addTheValClr(attVal1, attVal2);
                break;

        }
		//
		if(timeBtnType=="checkbox"){
			$("#tbdData input:[name^='b_']:checked").parent().addClass("k1");
			$("#tbdData input:[name^='b_']:not(:checked)").parent().removeClass("k1");
		}
        computeUnion(); // count the numbergruop
        return false;
    });



    return 1;
}

$.fn.addTheValClr = function(attVal1, attVal2) {
    if (attVal1 == null) {
        $(this).css('background-color', '#ffff8c');
    }
    else {
        $(this).css('background-color', '#ffff8c').attr(attVal1, attVal2);
    }
};

$.fn.clrTheValClr = function(attVal1) {
    if (attVal1 != null) {
        $(this).removeAttr(attVal1);
    }
    $(this).removeAttr('disabled').css('background-color', '');

}

// 连码 - 勾选
function crt_1To21ChkBox(rdata, bettype, subid, sTitle, iNumTr, disk, playgroup) {
    var str = "";
    var urlPre = "";
    var setBtnId = "";
    var setBtnName = "";
    var htmlTemp = '<tr class="td2">';
    var htmlTitle = '<th>项目</th><th>赔率</th><th class="bigRight">选择</th>';
    var trArr = new Array();
    var idx = 0;
    var dataLen = rdata.number.length;
    var i = 0;
    for (i = 0; i < iNumTr; i++) {
        trArr[i] = '';
    }
    var oNum = 0;
    var oRate = 0;
    var showTitleN = Math.floor(dataLen / iNumTr);
    var numClass = '';
    var numClassN = '';
    var rateClass = "";
    var inpVal = "";

    if ((dataLen % iNumTr) > 0) {
        showTitleN += 1;
    }
    str += '<caption class="bgClc_' + _gametype + '">' + sTitle + '</caption>';
    str += '<thead><tr class="title02_3d">';
    for (i = 0; i < showTitleN; i++) {
        str += htmlTitle;
    }
    str += '</tr></thead>';
    str += '<tbody align="center" id="tbdData">';
    for (i = 0; i < dataLen; i++) {
        idx = i % iNumTr;
        oNum = rdata.number[i];
        oRate = rdata.rates[i];
        urlPre = 'op.php?op=member_5h&fp=bet_fast&gametype=' + _gametype + '&disk=' + disk + '&palygroup=' + playgroup + '&bettype=' + bettype + '&subid=' + subid;
        setBtnId = 'b_' + subid + '_' + bettype + '_' + oNum;
        setBtnName = 'b_' + subid + '_' + bettype;
        //numClassN = oNum % 3;
        //if(numClassN == 0 ){numClassN = 3; }
        if (oNum > 18) {
            numClassN = 4;
        } else {
            numClassN = 2;
        }
        numClass = 'four5hB0' + numClassN;
        if (M.Rates[M.rateI] == undefined) {
            rateClass = '';
        }
        else if (M.Rates[M.rateI] != oRate) {
            rateClass = ' rc';
        }
        else {
            rateClass = '';
        }
        M.Rates[M.rateI] = oRate;
        M.rateI++;
        // inpVal = $('input[name="' + setBtnId + '"]').attr("checked");
        //if( inpVal == undefined ) { inpVal = ''; }
        trArr[idx] += '<th class="td6 ' + numClass + '">' + oNum + '</th>';
        //trArr[idx] += '<th><a href="' + urlPre + '" class="betRateNum" target="leftFrame">' + oRate + '</a></th>';
        trArr[idx] += '<th class="betRateNum' + rateClass + '">' + oRate + '</th>';
        trArr[idx] += '<td class="bigRight"><input type="checkbox" class="chkNum" name="' + setBtnId + '" value="' + oNum + '" /></td>'; // id="' + setBtnId + '"   
    }
    if (idx++ != iNumTr) {
        for (i = idx; i < iNumTr; i++) {
            trArr[i] += '<td></td><td></td><td></td>';
        }
    }
    str += htmlTemp + trArr.join('</tr><tr class=td2>') + '</tr></tbody>';
    return '<table class="tblMy3D" id="tblMy3DArea">' + str + '</table>';
}


// 连码 - 勾选直
function crt_1To21ChkBoxByP(rdata, bettype, subid, sTitle, iNumTr, disk, playgroup, pTitleArr) {
    var str = "";
    var urlPre = "";
    var setBtnId = "";
    var setBtnName = "";
    var htmlTemp = '<tr class="td2">';
    var htmlTitle = '<th class="bigTop">项目</th><th class="bigTop">赔率</th><th class="bigTop bigRight">选择</th>';
    var trArr = new Array();
    var idx = 0;
    var dataLen = rdata.number.length;
    var i = 0;
    var oNum = 0;
    var oRate = 0;
    var showTitleN = Math.floor(dataLen / iNumTr);
    var numClass = '';
    var numClassN = '';
    if ((dataLen % iNumTr) > 0) {
        showTitleN += 1;
    }
    str += '<caption class="bgClc_' + _gametype + '">' + sTitle + '</caption>';
    var j = 0;
    var pTitleLen = pTitleArr.length;
    var rateClass = "";
    var inpVal = "";
    for (j = 0; j < pTitleLen; j++) {
        str += '<thead><tr class="title02_3d"><th>位别</th>';
        for (i = 0; i < showTitleN; i++) {
            str += htmlTitle;
        }
        str += '</tr></thead>';
        for (i = 0; i < iNumTr; i++) {
            trArr[i] = '';
        }

        trArr[0] = '<th rowspan="' + iNumTr + '" class="td15">' + pTitleArr[j] + '</th>';
        str += '<tbody align="center" id="tbdData_' + j + '">';
        for (i = 0; i < dataLen; i++) {
            idx = i % iNumTr;
            oNum = rdata.number[i];
            oRate = rdata.rates[i];
            urlPre = 'op.php?op=member_5h&fp=bet_fast&gametype=' + _gametype + '&disk=' + disk + '&palygroup=' + playgroup + '&bettype=' + bettype + '&subid=' + subid;
            setBtnId = 'b_' + subid + '_' + bettype + '_' + oNum;
            setBtnName = 'b_' + subid + '_' + bettype;
            //numClassN = oNum % 3;
            //if(numClassN == 0 ){numClassN = 3; }
            if (oNum > 18) {
                numClassN = 4;
            } else {
                numClassN = 2;
            }
            numClass = 'four5hB0' + numClassN;
            if (M.Rates[M.rateI] == undefined) {
                rateClass = '';
            }
            else if (M.Rates[M.rateI] != oRate) {
                rateClass = ' rc';
            }
            else {
                rateClass = '';
            }
            M.Rates[M.rateI] = oRate;
            M.rateI++;
            // inpVal = $('input[name="' + setBtnId + '"]').attr("checked");
            //if( inpVal == undefined ) { inpVal = ''; }
            trArr[idx] += '<th class="td6 ' + numClass + '">' + oNum + '</th>';
            //trArr[idx] += '<th><a href="' + urlPre + '" class="betRateNum" target="leftFrame">' + oRate + '</a></th>';
            trArr[idx] += '<th class="betRateNum' + rateClass + '">' + oRate + '</th>';
            trArr[idx] += '<td class="bigRight"><input type="checkbox" class="chkNum" name="' + setBtnId + '" value="' + oNum + '" /></td>'; // id="' + setBtnId + '"   
        }
        if (idx++ != iNumTr) {
            for (i = idx; i < iNumTr; i++) {
                if (j == 0) {
                    trArr[i] += '<td colspan="3"><input type="button" value="包牌" class="colorBtnGray" id="btnCopyToOther" /><a class="tooltipsSite" href="#tooltipsSite">(说明)<span><div>1) 勾选前位号码(至多6码)<br /> 2) 按下[包牌]按钮后,中/后位将与前位号码同步</div></span></a></td>';
                } else {
                    trArr[i] += '<td></td><td></td><td></td>';
                }

            }

        }
        str += htmlTemp + trArr.join('</tr><tr class=td2>') + '</tr></tbody>';
    }

    return '<table class="tblMy3D" id="tblMy3DAreaS">' + str + '</table>';    //  id="tblMy3DArea"
}

function crt_rdoRC(radValArr, rdoRCID, mbRate) {
    var str = ['', ''];
    var i = 0;
    var l = radValArr.length;
    var chkStr = '';
    var chkClr = '';
    var chkClr02 = '';
    var rateS = 0;
    var rateM = 0;
    for (i = 0; i < l; i++) {
        if (rdoRCID == radValArr[i][0]) {
            chkStr = ' checked ';
            chkClr = ' class="bgImg_' + _gametype + '"';
            chkClr02 = ' class="msgBox-yellow"';
        } else {
            chkStr = '';
            chkClr = '';
            chkClr02 = '';
        }
        if (mbRate[i].rbet == radValArr[i][0]) {
            rateS = mbRate[i].ratesS;
            rateM = mbRate[i].ratesM;
        } else {
            rateS = 0;
            rateM = 0;
        }
        str[0] += '<td' + chkClr + '><label><input type="radio" value="' + radValArr[i][0] + '" name="rcbettype" onclick="javascript:$().getAjaxRatedata(_lotto_id,_gametype,_playtype);" ' + chkStr + ' />' + radValArr[i][1] + '</label></td>';
        str[1] += '<td' + chkClr02 + '><font color="#DC0300">最大 ' + rateM + '</font><br /><font color="#181789">最小 ' + rateS + '</font></td>';
    }

    return '<table class="tblMy3D"><tr class="bgClc_' + _gametype + '">' + str[0] + '</tr><tr class="td2">' + str[1] + '</tr></table>';
}
// rdata, bettype, subid, sTitle, iNumTr, disk, playgroup
function crt_2face_com(rdata, bettype, subBettype, sTitle, showTitleArr, rowSpanN, tdNum, disk, playgroup, bgClass, xyid) {
    var setBtnId = "";
    var str = '';
    var strTitle = "";
    var sNum = "";
    var sRate = "";
    var num = 0;
    var setBtnId = "";
    var nextI = -1;        // 可秀玩法
    var i = 0;
    var l = 0;
    var l2 = 0;
    var littletotal = 0;
    var classCount = 0;
    var titleTemp = '';
    var colTemp = '';
    var tempCount = 0;
    var urlPre = '';
    var showClass = '';
    var rateClass = "";
    var inpVal = "";
    str = '<tr class="td2">';
    for (i = 0, l = rdata.length; i < l; i++) {
        if (i == 0 && sTitle != '') {
            str += '<th class="td15">' + sTitle + '</th>';
        }
        l2 = showTitleArr[i].length;
        for (var j = 0; j < l2; j++) {  // 双面
            tempCount++;
            sNum = rdata[i].number[j];
            sRate = rdata[i].rates[j];
            setBtnId = setBtnId = 'b_' + subBettype[i] + '_' + bettype[i] + '_' + sNum;
            urlPre = 'op.php?op=member_5h&fp=bet_fast&gametype=' + _gametype + '&disk=' + disk + '&palygroup=' + playgroup + '&bettype=' + bettype[i] + '&subid=' + subBettype[i] + '&num=' + sNum + '&xyid=' + xyid + '&rate=' + sRate;
            if (bgClass != '') {
                showClass = ' ' + bgClass + sNum;
            } else {
                showClass = '';
            }
            if (M.Rates[M.rateI] == undefined) {
                rateClass = '';
            }
            else if (M.Rates[M.rateI] != sRate) {
                rateClass = ' class="rc"';
            }
            else {
                rateClass = '';
            }
            M.Rates[M.rateI] = sRate;
            M.rateI++;
            inpVal = $('input[name="' + setBtnId + '"]').val();
            if (inpVal == undefined) {
                inpVal = '';
            }
            str += '<th class="title02_3d' + showClass + '" nowrap>' + showTitleArr[i][j] + '</th>';
            str += '<th' + rateClass + '><a href="' + urlPre + '" class="betRateNum" target="leftFrame">' + sRate + '</a></th>';
            str += '<td><input type="text" size="3"  value="' + inpVal + '" name="' + setBtnId + '" /></td>';
        }
    }
    if (tempCount < tdNum) {
        for (i = 0; i < (tdNum - tempCount); i++) {
            str += '<td></td><td></td><td></td>';
        }
    }
    return str;

}
// for eazy type
function crt_2face_com_Vertical(rdata, bettype, subBettype, sTitle, showTitleArr, rowSpanN, tdNum, disk, playgroup, bgClass, xyid) {
    var setBtnId = "";
    var str = '';
    var strTitle = "";
    var sNum = "";
    var sRate = "";
    var num = 0;
    var setBtnId = "";
    var nextI = -1;        // 可秀玩法
    var i = 0;
    var l = 0;
    var l2 = 0;
    var littletotal = 0;
    var classCount = 0;
    var titleTemp = '';
    var colTemp = '';
    var tempCount = 0;
    var urlPre = '';
    var showClass = '';
    var rateClass = "";
    var inpVal = "";
    str = '<table class="tblMy3D" style="width:185px;table-layout:fixed; ">';
    for (i = 0, l = rdata.length; i < l; i++)
    {
        if (i == 0 && sTitle != '') {
            str += '<th class="bgImg_' + _gametype + '" colspan="3">' + sTitle + '</th>';
        }
        l2 = showTitleArr[i].length;
        for (var j = 0; j < l2; j++) {  // 双面
            tempCount++;
            sNum = rdata[i].number[j];
            sRate = rdata[i].rates[j];
            setBtnId = setBtnId = 'b_' + subBettype[i] + '_' + bettype[i] + '_' + sNum;
            urlPre = 'op.php?op=member_5h&fp=bet_fast&gametype=' + _gametype + '&disk=' + disk + '&palygroup=' + playgroup + '&bettype=' + bettype[i] + '&subid=' + subBettype[i] + '&num=' + sNum + '&xyid=' + xyid + '&rate=' + sRate;
            if (bgClass != '') {
                showClass = ' ' + bgClass + sNum;
            } else {
                showClass = '';
            }
            if (M.Rates[M.rateI] == undefined) {
                rateClass = '';
            }
            else if (M.Rates[M.rateI] != sRate) {
                rateClass = ' class="rc"';
            }
            else {
                rateClass = '';
            }
            M.Rates[M.rateI] = sRate;
            M.rateI++;
            inpVal = $('input[name="' + setBtnId + '"]').val();
            if (inpVal == undefined) {
                inpVal = '';
            }
            str += '<tr class="td2">';
            str += '<th class="title02_3d' + showClass + '" nowrap>' + showTitleArr[i][j] + '</th>';
            str += '<th' + rateClass + '><a href="' + urlPre + '" class="betRateNum" target="leftFrame">' + sRate + '</a></th>';
            str += '<td><input type="text" size="3"  value="' + inpVal + '" name="' + setBtnId + '" /></td>';
            str += '</tr>';
        }
    }
    str += '</table>';
    return str;
}

// n1~n5 - money
function crt_1To21(rdata, bettype, subid, sTitle, iNumTr, disk, playgroup, xyid) {
    var str = "";
    var urlPre = "";
    var setBtnId = "";
    var htmlTemp = '<tr class="td2">';
    var htmlTitle = '<th>号码</th><th>赔率</th><th>金额</th>';
    var trArr = new Array();
    var idx = 0;
    var dataLen = rdata.number.length;
    var i = 0;
    for (i = 0; i < iNumTr; i++) {
        trArr[i] = '';
    }
    var oNum = 0;
    var oRate = 0;
    var showTitleN = Math.floor(dataLen / iNumTr);
    var numClass = '';
    var numClassN = 0;
    var rateClass = "";
    var inpVal = "";
    if ((dataLen % iNumTr) > 0) {
        showTitleN += 1;
    }
    str += '<caption class="bgClc_' + _gametype + '">' + sTitle + '</caption>';
    str += '<thead><tr class="td15">';
    for (i = 0; i < showTitleN; i++) {
        str += htmlTitle;
    }
    str += '</tr></thead>';
    str += '<tbody align=center id="tbdData">';
    for (i = 0; i < dataLen; i++) {
        idx = i % iNumTr;
        oNum = rdata.number[i];
        oRate = rdata.rates[i];
        urlPre = 'op.php?op=member_5h&fp=bet_fast&gametype=' + _gametype + '&disk=' + disk + '&palygroup=' + playgroup + '&bettype=' + bettype + '&subid=' + subid + '&num=' + oNum + '&xyid=' + xyid + '&rate=' + oRate;
        setBtnId = 'b_' + subid + '_' + bettype + '_' + oNum;
        //numClassN = oNum % 4;
        //if(numClassN == 0 ){numClassN = 4; }
        if (oNum > 18) {
            numClassN = 4;
        } else {
            numClassN = 2;
        }
        numClass = 'four5hB0' + numClassN;
        if (M.Rates[M.rateI] == undefined) {
            rateClass = '';
        }
        else if (M.Rates[M.rateI] != oRate) {
            rateClass = ' class="rc"';
        }
        else {
            rateClass = '';
        }
        M.Rates[M.rateI] = oRate;
        M.rateI++;
        inpVal = $('input[name="' + setBtnId + '"]').val();
        if (inpVal == undefined) {
            inpVal = '';
        }
        trArr[idx] += '<th class="title02_3d ' + numClass + '">' + oNum + '</th>';
        trArr[idx] += '<th' + rateClass + '><a href="' + urlPre + '" class="betRateNum" target="leftFrame">' + oRate + '</a></th>';
        trArr[idx] += '<td><input type="text" size="3"  value="' + inpVal + '" name="' + setBtnId + '" /></td>';
    }
    if (idx++ != iNumTr) {
        for (i = idx; i < iNumTr; i++) {
            trArr[i] += '<td></td><td></td><td></td>';
        }
    }
    str += htmlTemp + trArr.join('</tr><tr class=td2>') + '</tr>';
    str += '</tbody>';
    return str;
}



// quick button group
function crt_quick(showArr, checkedIdx) {
    var str = '';
    var quickArr = ['连碰', '胆拖'];
    var quickArrL = quickArr.length;
    var quickValArr = ['a', 'b'];
    var chkStr = '';
    for (var i = 0; i < quickArrL; i++) {
        if (i == checkedIdx) {
            chkStr = ' checked';
        } else {
            chkStr = '';
        }
        if (showArr[i] > 0) {
            str += '<label><input type="radio"  class="quick5hType" value="' + quickValArr[i] + '" name="quick5h" ' + chkStr + ' />' + quickArr[i] + '</label>';
        }
    }
    return str;
}

// quick button group
function crt_quick03(showArr, checkedIdx) {
    var str = '';
    var quickArr = ['前', '中', '后'];
    var quickArrL = quickArr.length;
    var quickValArr = ['c', 'd', 'e'];
    var chkStr = '';
    for (var i = 0; i < quickArrL; i++) {
        if (i == checkedIdx) {
            chkStr = ' checked';
        } else {
            chkStr = '';
        }
        if (showArr[i] > 0) {
            str += '<label><input type="radio"  class="quick5hType" value="' + quickValArr[i] + '" name="quick5h02" ' + chkStr + ' />' + quickArr[i] + '</label>';
        }
    }
    return str;
}

function crt_quick02(quick01Id, showArr) {
    var str = '';
    var quickArr = ['&nbsp;', '头', '尾', '中发白', '方位', '快速'];
    var quickArrL = quickArr.length;
    var quickValArr = [['单', '双', '大', '小', '合单', '合双'], [' 0 ', ' 1 ', ' 2 '], [' 0 ', ' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ', ' 6 ', ' 7 ', ' 8 ', ' 9 '], ['中', '发', '白'], ['东', '南', '西', '北'], ['全选']];
    var quickValIDArr = [['A1', 'A2', 'B1', 'B2', 'C1', 'C2'], ['G0', 'G1', 'G2'], ['H0', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'H7', 'H8', 'H9'], ['I1', 'I2', 'I3'], ['J1', 'J2', 'J3', 'J4'], ['K1']];
    var quickValArrL = 0;
    var chkStr = '';
    var quick01IdStr = 'quick02_' + quick01Id + '_';
    var i = 0;
    var j = 0;
    var oQ = 0;
    var oID = 0;
    var sClass = 'colorBtnGray';
    for (i = 0; i < quickArrL; i++) {
        if (showArr[i] > 0) {
            if (i == 3) {
                str += '<br />';
            }
            str += '&nbsp;&nbsp;<label id="' + quick01IdStr + i + '">' + quickArr[i];
            oQ = quickValArr[i];
            oID = quickValIDArr[i];
            for (j = 0, quickValArrL = oQ.length; j < quickValArrL; j++) {
                str += '<input type="button" value="' + oQ[j] + '" id="qckBtn_' + oID[j] + '" class="' + sClass + '" />';
            }
            str += '</label>';
        }
    }
    return str;
}

// -----------------------------------------------------------------------------
// function
// -----------------------------------------------------------------------------

// change money input to fast checkbox button 
$.fn.timebtnTypeToCheckbox = function() {
	mysetcookie("timebtnType","checkbox",1);
    $("input:hidden#timebtnType").val("checkbox");
    $("#myDivTbl input:text[name^='b_']").each(function() {
		var o=$(this).closest('td');
		o.html("<input type=\"checkbox\" value=\"1\" name=\"" + $(this).attr("name") + "\" style=\"display:none\" />");
		o.bind("click",function(e){
			var inpu=$(this).find("input");
			if(inpu.attr("checked"))
			{
				$(this).removeClass("k1");	
				inpu.attr("checked",false);
			}
			else
			{
				$(this).addClass("k1");	
				inpu.attr("checked",true);
			}
		});
        
        return true;
    });
	$("input:button#betByCheckBox").addClass("btn_on");
    $("input:button#betByTextMoney").removeClass("btn_on");
    //$("input:button#betByCheckBox").hide();
    //$("input:button#betByTextMoney").show();
    $("input:button#btnSetMyNum").attr("disabled", "true");
};

// chang fast to money input
$.fn.timebtnTypeText = function() {
	mysetcookie("timebtnType","text",1);
    $("input:hidden#timebtnType").val("text");
    $("input:checkbox[name^='b_']").each(function() {
		var o=$(this).closest('td');
		o.html("<input type=\"text\" value=\"\" name=\"" + $(this).attr("name") + "\" size=\"3\" />");
		o.removeClass("k1");
		o.unbind("click");
        return true;
    });
	$("input:button#betByTextMoney").addClass("btn_on");
    $("input:button#betByCheckBox").removeClass("btn_on");
    //$("input:button#betByTextMoney").hide();
   // $("input:button#betByCheckBox").show();
    $("input:button#btnSetMyNum").removeAttr("disabled");
};
function leftPar(v)
{
	if(parseInt(v)<=9)
		return "0"+v;
	else
		return v;	
}
var _refstap=30;
$.fn.showNowTime = function() {
    var thisObj = $(this);
    var str = "";
    if (_timestap >= 0) {
        timediff = _timestap;
    days = Math.floor(timediff / (86400));   // 60 * 60 * 24
  	timediff -= days * (86400);
  	hours = Math.floor(timediff / (3600));  // 60 * 60
  	timediff -= hours * (3600);	
  	mins = Math.floor(timediff / (60));
  	timediff -= mins * (60);	
  	secs = Math.floor(timediff);
    str += "<span style='margin-right:10px'><div style='float:left;width:150px'>距离封盘：";
    if (days > 0 ) str += "<b>" + leftPar(days) + "</b> 天 ";
    if (hours > 0) str += "<b>" + leftPar(hours) + "</b>:";
    if (mins > 0) str += "<b>" + leftPar(mins) + "</b>:";
    str += "<b>" + leftPar(secs) + "</b></div><div style='float:left;width:150px'>距离开奖：";
	//
	timediff2=_timestap+60;
	days = Math.floor(timediff2 / (86400));   // 60 * 60 * 24
  	timediff2 -= days * (86400);
  	hours = Math.floor(timediff2 / (3600));  // 60 * 60
  	timediff2 -= hours * (3600);	
  	mins = Math.floor(timediff2 / (60));
	timediff2 -= mins * (60);	
  	secs = Math.floor(timediff2);
	if (days > 0 ) str += "<b>" + leftPar(days) + "</b> 天 ";
    if (hours > 0) str += "<b>" + leftPar(hours) + "</b>:";
    if (mins > 0) str += "<b>" + leftPar(mins) + "</b>:";
	str += "<b>" + leftPar(secs) + "</b></div><div style='float:left;width:50px;text-align:right;'>"+leftPar(_refstap)+"秒</div></span>";
	_refstap--;
	if(_refstap==0) _refstap=30;
    _timestap-=1;
    } else {
        str += "<font color=red><b>【" + _gametypeStr + "】已经截止下注！</b></font>";
        if (M.RatesTimeId) {
            clearTimeout(M.RatesTimeId);
        }
        setTimeout('parent.mainFrame.location.reload()', 1000);
        setTimeout('parent.leftFrame.location.reload()', 1000);
    }
    $(this).html(str);
    _now.setTime(_now.getTime() + 1000);
    setTimeout(function() {
        $(thisObj).showNowTime();
    }, 1000);
};

// 显示讯息方块(取代alert 因alert会使目前时间与截止下注时间暂时停止计算)
$.fn.showMyMsgBox = function(msg) {
    $("div#show3dmsg").html("<span class=\"error3d\">" + msg + "</span><br /><input type=\"button\" align=\"center\" id=\"btnOkMsg\" class=\"btnchoice\" value=\"确定\" onclick=\"javascript:$().closeMyMsgBox();\" />");
    $("div#show3dmsg").addClass("show3dmsg").show();
};

$.fn.closeMyMsgBox = function() {
    $("div#show3dmsg").removeClass("show3dmsg").hide();
};

//  更新率赔率禁止使用
$.fn.disAreaObj = function() {
    $("select#xyidSlc").attr("disabled", "disabled");
    $("select#slcDisk").attr("disabled", "disabled");
    $("input:button#betByCheckBox").attr("disabled", "disabled");
    $("input:button#betByTextMoney").attr("disabled", "disabled");
};

$.fn.redisAreaObj = function() {
    $("select#xyidSlc").removeAttr("disabled");
    $("select#slcDisk").removeAttr("disabled");
    $("input:button#betByCheckBox").removeAttr("disabled");
    $("input:button#betByTextMoney").removeAttr("disabled");
};

// count group number
function computeUnion() {
    $('#B5hTypeSpan01Msg').empty();
    if (_rxcxChkN > -1) {
        var tempSValArr = [];
        var dobuledNum = 0;
        if (_rxcxChkN02) { // 胆
            if ($('#tblMy3DArea input:disabled:checked').length < _rxcxChkN) {
                $('#tblMy3DArea input:checked').attr('disabled', 'disabled');
                $('#tblMy3DArea input:checked:disabled').each(function(idx, oVal) {
                    tempSValArr.push($(oVal).val());
                    return true;
                });
                $('#B5hTypeSpan01Msg').html('[<span id="B5hTypeSpan01Span">' + tempSValArr.join(",") + '</span>]<br />');
            } else {
                var temp01 = '';
                var temp02 = '';
                $('#tblMy3DArea input:disabled:checked').each(function(idx, oVal) {
                    tempSValArr.push($(oVal).val());
                    return true;
                });
                temp01 = tempSValArr.join(",");
                tempSValArr = [];
                dobuledNum = 0;
                $('#tblMy3DArea input:checked:not(:disabled)').each(function(idx, oVal) {
                    tempSValArr.push($(oVal).val());
                    dobuledNum++;
                    return true;
                });
                temp02 = tempSValArr.join(",");
                $('#B5hTypeSpan01Msg').html('[<span id="B5hTypeSpan01Span">' + temp01 + '</span>][<span id="B5hTypeSpan02Span">' + temp02 + '</span>] 共 ' + dobuledNum + ' 组<br />');
            }
        } else { // 碰
            // 限制
            if ($('#tblMy3DArea input:checked').length == _maxPoun) {
                $('#tblMy3DArea input:not(:checked)').attr("disabled", "disabled");
            } else {
                $('#tblMy3DArea input').removeAttr("disabled");
            }
            $('#tblMy3DArea input:checked').each(function(idx, oVal) {
                tempSValArr.push($(oVal).val());
                dobuledNum++;
                return true;
            });
            if (dobuledNum < _rxcxChkN) {
                $('#B5hTypeSpan01Msg').html('[<span id="B5hTypeSpan01Span">' + tempSValArr.join(",") + '</span>]共 0 组<br />');
            } else {
                var betUnionLength = tempSValArr.length;
                //组合数 
                switch (_rxcxChkN) {
                    case 0:
                        var bet_Length = betUnionLength;
                        break;
                    case 1:
                        var bet_Length = betUnionLength * (betUnionLength - 1) / 2;
                        break;
                    case 2:
                        var bet_Length = betUnionLength * (betUnionLength - 1) * (betUnionLength - 2) / 6;
                        break;
                    case 3:
                        var bet_Length = betUnionLength * (betUnionLength - 1) * (betUnionLength - 2) * (betUnionLength - 3) / 24;
                        break;
                    case 4:
                        var bet_Length = betUnionLength * (betUnionLength - 1) * (betUnionLength - 2) * (betUnionLength - 3) * (betUnionLength - 4) / 120;
                        break;
                    default:
                        alert('error rxcxChkN');
                        return false;
                        break;
                }

                $('#B5hTypeSpan01Msg').html('[<span id="B5hTypeSpan01Span">' + tempSValArr.join(",") + '</span>]共 ' + bet_Length + ' 组<br />');
            }
        }
    }

}


// count group number by num no sort
function computeUnionS() {
    $('#B5hTypeSpan03Msg').empty();
    if (_rxcxChkN > -1) {
        var tbdNum = $('#tblMy3DAreaS tbody').length;
        var sendDataArr = [];
        var i = 0;
        var okL = 0;
        var showStr = '';
        var bet_Length = 1;
        // tblMy3DAreaS check for enabled numbers
        if ($('#tblMy3DAreaS input:checked').length == _maxPoun) {
            $('#tblMy3DAreaS input:not(:checked)').attr("disabled", "disabled");
        }
        else {
            $('#tblMy3DAreaS input').removeAttr("disabled");
        }

        for (i = 0; i < tbdNum; i++) {
            sendDataArr[i] = [];
            $('#tbdData_' + i + ' input:checked').each(function(idx, oVal) {
                sendDataArr[i].push($(oVal).val());
                return true;
            });
            if (sendDataArr[i].length > 0) {
                okL++;
            }
            if (i) {
                showStr += ' X ';
            }
            showStr += '[<span id="B5hTypeSpan03' + i + 'Span">' + sendDataArr[i].join(',') + '</span>]';
        }

        if (okL == tbdNum) {
            bet_Length = 0;
            if (okL == 2) {
                var j = 0;
                for (i = 0; i < sendDataArr[0].length; i++) {
                    for (j = 0; j < sendDataArr[1].length; j++) {
                        if (sendDataArr[0][i] != sendDataArr[1][j]) {
                            bet_Length++;
                        }
                    }
                }
            } else {
                var j = 0;
                var k = 0;
                for (i = 0; i < sendDataArr[0].length; i++) {
                    for (j = 0; j < sendDataArr[1].length; j++) {
                        if (sendDataArr[0][i] == sendDataArr[1][j]) {
                            continue;
                        }
                        for (k = 0; k < sendDataArr[2].length; k++) {
                            if (sendDataArr[0][i] == sendDataArr[2][k]) {
                                continue;
                            }
                            if (sendDataArr[1][j] == sendDataArr[2][k]) {
                                continue;
                            }
                            bet_Length++;
                        }
                    }
                }
            }
            $('#B5hTypeSpan03Msg').html(showStr + '共 ' + bet_Length + ' 组<br />');
        }
        else {
            $('#B5hTypeSpan03Msg').html(showStr + '共 0 组<br />');
        }
    }
}

function submitCom() {
    if (_rxcxChkN > -1) { // rxcx Special
        if ($("input:text#setMomney").val() < 1) {
            $().showMyMsgBox("请于“金额”右侧之文字方块中输入下注金额");
            $("input:text#setMomney").focus();
            return false;
        } else if ($("input:text#setMomney").val() < _betmin) {
            $().showMyMsgBox("下注金额不能小于最低下注额(" + _betmin + "元)");
            $("input:text#setMomney").focus();
            return false;
        } else {
            if (_rxcxChkN02) { // 胆
                var B5hTypeSpan01Span = $('#B5hTypeSpan01Span').text();
                var B5hTypeSpan02Span = $('#B5hTypeSpan02Span').text();
                if (B5hTypeSpan01Span.length < 2) {
                    $().showMyMsgBox("请至少选择“" + _rxcxChkN + "”胆");
                    return false;
                }
                if (B5hTypeSpan02Span.length < 2) {
                    $().showMyMsgBox("请至少选择 1 托");
                    return false;
                }

                if (B5hTypeSpan02Span.split(",").length > _maxPoun) {
                    $().showMyMsgBox("最多只能选择 " + _maxPoun + " 托");
                    return false;
                }

                $('#B5hTypeSpan01').val(B5hTypeSpan01Span);
                $('#B5hTypeSpan02').val(B5hTypeSpan02Span);
            } else {
                var B5hTypeSpan01Span = $('#B5hTypeSpan01Span').text();
                var B5hTypeSpan01SpanArr = B5hTypeSpan01Span.split(",");
                var okrxcxChkN = _rxcxChkN - 0 + 1;
                if (B5hTypeSpan01SpanArr.length < okrxcxChkN) {
                    $().showMyMsgBox("请至少选择 " + okrxcxChkN + " 个碰数");
                    return false;
                }
                if (B5hTypeSpan01SpanArr.length > _maxPoun) {
                    $().showMyMsgBox("至多选择 " + _maxPoun + " 个碰数");
                    return false;
                }
                $('#B5hTypeSpan01').val(B5hTypeSpan01Span);
            }
            $("#B5hTypeMon").val($("input:text#setMomney").val());
            $("#tbdData input[name^='b_']").removeAttr('checked');
        }
    } else {
        switch ($("input:hidden#timebtnType").val()) {
            case "text": //text
                if ($("input:text[name^='b_'][value!='']").not("[value='*']").size() < 1) {
                    $().showMyMsgBox("请在文字方块中填入要下注的金额；<br />或使用“转送”钮将“*”字转为金额值");
                    return false;
                }
                break;

            case "checkbox": // checkbox
                if ($("input:checkbox[name^='b_']:checked").size() < 1) {
                    $().showMyMsgBox("请勾选要下注的内容");
                    return false;
                } else if ($("input:text#setMomney").val() < 1) {
                    $().showMyMsgBox("请于“金额”右侧之文字方块中输入下注金额");
                    $("input:text#setMomney").focus();
                    return false;
                } else if ($("input:text#setMomney").val() < _betmin) {
                    $().showMyMsgBox("下注金额不能小于最低下注额(" + _betmin + "元)");
                    $("input:text#setMomney").focus();
                    return false;
                } else {
                    $("input:checkbox[name^='b_']:checked").val($("input:text#setMomney").val())
                }
                break;
        }
    }

    $("form input:submit").add("form input:button").attr("disabled", "disabled");
    $("input#xyid").attr("value", $("select#xyidSlc option:selected").val());//XY盘类的值
    $("input#disk").attr("value", $("select#slcDisk option:selected").val());
    return true;
}

function submitComS() {
    if ($("input:text#setMomney").val() < _betmin) {
        $().showMyMsgBox("下注金额不能小于最低下注额(" + _betmin + "元)");
        $("input:text#setMomney").focus();
        return false;
    }
    if (_rxcxChkN > -1) {
        var tbdNum = $('#tblMy3DAreaS tbody').length;
        var sendDataArr = '';
        var i = 0;
        var okL = 0;
        for (i = 0; i < tbdNum; i++) {
            sendDataArr = $('#B5hTypeSpan03' + i + 'Span').text();
            if (sendDataArr.length < 1) {
                $().showMyMsgBox("勾选个数不足");
                return false;
            }
            else {
                okL++;
            }
            $('#B5hTypeSpan0' + (i * 1 + 1)).val(sendDataArr);
        }
        if (okL == tbdNum) {
            $("#B5hTypeMon").val($("input:text#setMomney").val());
            $("#tbdData input[name^='b_']").removeAttr('checked');
            $("form input:submit").add("form input:button").attr("disabled", "disabled");
            $("input#xyid").attr("value", "0");//XY盘类的值
            $("input#disk").attr("value", $("select#slcDisk option:selected").val());
            return true;
        } else {
            return false;
        }
    }
    return false;
}
// -----------------------------------------------------------------------------
$(function() {

    // default value for checkbox or money input
    $("input#xyid").attr("value", $("select#xyidSlc option:selected").val());//XY盘类的值
    $("input#disk").attr("value", $("select#slcDisk option:selected").val());
    //var chkStr = ',r1c1,r2c2,r3c2,r3c3,r4c3,r5c3,';
    //if(chkStr.indexOf(','+ _playtype +',') > -1){
    if (_playtype == 'rc') {
        $("#spanChgBetBtn").hide();
        $("input:hidden#timebtnType").val('checkbox');
        $("#xyidSlc").hide();
    }
    //else if ($("input:hidden#timebtnType").val() == "text") {
    //    $("input:button#betByTextMoney").hide();
    //} else {
    //    $("input:button#betByCheckBox").hide();
    //}

    // time of now
    $("span#showNowTime").showNowTime();

    $("div#mainPageData").hide();

    // get rate data and show table
    $().getAjaxRatedata(_lotto_id, _gametype, _playtype);

    // change to money input
    $("input:button#betByCheckBox").bind('click', function() {
        $().timebtnTypeToCheckbox();
    });
    // change to fast checkbox 
    $("input:button#betByTextMoney").bind('click', function() {
        $().timebtnTypeText();
    });

    // “transfer”
    $("input:button#btnSetMyNum").bind('click', function() {
        var setMomney = $("input:text#setMomney").val();
        if (setMomney < 1) {
            $().showMyMsgBox("请于“金额”右侧之文字方块中输入要转送之金额");
            $("input:text#setMomney").focus();
            return false;
        } else if (setMomney < _betmin) {
            $().showMyMsgBox("下注金额不能小于最低下注额(" + _betmin + "元)");
            $("input:text#setMomney").focus();
            return false;
        } else {
            $("input:text[name^='b'][value='*']").val(setMomney);
            $("input:text#setMomney").val("");
        }
    });

    // before submit
    $("form").submit(function() {
        var rdoRCID = ',' + $('input[name="rcbettype"]:checked').val() + ',';
        var chkRdoStr = ',12,15,';
        if (chkRdoStr.indexOf(rdoRCID) > -1) {
            return submitComS();
        }
        else {
            return submitCom();
        }
    });

    $("input:button").hover(
            function() {
                this.style.color = '#0000FF';
            }
    , function() {
        this.style.color = '';
    }
    );

    // change rate by XY disk
    $("select#xyidSlc").change(function() {
        $("input#xyid").attr("value", $("select#xyidSlc option:selected").val());
        $().getAjaxRatedata(_lotto_id, _gametype, _playtype);
    });

    // change rate by a,b,c,d disk
    $("select#slcDisk").change(function() {
        if (M.RatesTimeId) {
            clearTimeout(M.RatesTimeId);
        }
        $("input#disk").attr("value", $("select#slcDisk option:selected").val());
        M.Rates = new Array();
        $().getAjaxRatedata(_lotto_id, _gametype, _playtype);
    });

    // reset button
    $("input#myreset").click(function() {
        var timebtnType = $("input:hidden#timebtnType").val();
        var attVal1 = '';
        switch (timebtnType) {
            case 'text':
                attVal1 = 'value';
                break;
            case 'checkbox':
                attVal1 = 'checked';
                break;
            default:
                alert('error type');
                return false;
        }
        var oObj = $("#tbdData input:[name^='b_']");
        oObj.clrTheValClr(attVal1);
        if ($("#tblMy3DAreaS").length > 0) {
            $("#tblMy3DAreaS input:[name^='b_']").clrTheValClr('checked');
        }
        $('input.quick5hType:checked').click();
    });

    // show fast bet button
    show_setMyNum2(_playtype);

    // show number tbl
    if (_playtype != 'rc' && chgBallArr.length > 0) {
        $('.disClc').click(function() {
            $('.onClc').removeClass('onClc');
            $(this).addClass("onClc");
            var myIDX = $(this).attr("id").substr(5);
            $('#chgBallAreaStr').empty().append(chgBallArr[myIDX]);
            $('#chgBallAreaStr td:even').css("background-color", "#e7ebef");
        });
        $('.disClc:eq(0)').click();
        if (_maxTotal > 0) {
            $('#maxDisBall td').each(function(idx, ele) {
                if ($(ele).text() == _maxTotal) {
                    $(ele).css({'color': '#FA0300', 'font-weight': '900'});
                }
            });
        }
        if (_maxTotal0 > 0) {
            $('#maxDisBall0 td').each(function(idx, ele) {
                if ($(ele).text() == _maxTotal0) {
                    $(ele).css({'color': '#FA0300', 'font-weight': '900'});
                }
            });
        }
    }

}); 
$(document).ready(function(e) {
    $("#myreset").bind("click",function(){$(".k1").removeClass("k1");});
});